rm(list = ls())
load("dataBJPOLS.RData")

inst.1 <- "judgeiv_hd"
endo.1 <- "pti"
outc.1 <- "vote_post"

time.controls <- "as.factor(court_time1) + as.factor(court_time2) + as.factor(court_dow) + as.factor(severity)"
demo.controls <- "age + I(age^2) +  as.factor(race4) + female + vote_pre + as.factor(noteli) + regis_before"
case.controls <- "as.factor(any_drug) +  as.factor(any_weapon) +  as.factor(any_prop) + as.factor(any_prior_case)"

table1 <- rbind(c(mean(last.cases$pti, na.rm = T), sd(last.cases$pti, na.rm = T),
  mean(last.cases$pti[last.cases$pti == 1], na.rm = T), sd(last.cases$pti[last.cases$pti == 1], na.rm = T),
  mean(last.cases$pti[last.cases$pti == 0], na.rm = T), sd(last.cases$pti[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$daysjail_t > 365, na.rm = T), sd(last.cases$daysjail_t > 365, na.rm = T),
  mean(last.cases$daysjail_t[last.cases$pti == 1] > 365, na.rm = T), sd(last.cases$daysjail_t[last.cases$pti == 1] > 365, na.rm = T),
  mean(last.cases$daysjail_t[last.cases$pti == 0] > 365, na.rm = T), sd(last.cases$daysjail_t[last.cases$pti == 0] > 365, na.rm = T)),
c(mean(last.cases$daysjail_t, na.rm = T), sd(last.cases$daysjail_t, na.rm = T),
  mean(last.cases$daysjail_t[last.cases$pti == 1], na.rm = T), sd(last.cases$daysjail_t[last.cases$pti == 1], na.rm = T),
  mean(last.cases$daysjail_t[last.cases$pti == 0], na.rm = T), sd(last.cases$daysjail_t[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$age, na.rm = T), sd(last.cases$age, na.rm = T),
  mean(last.cases$age[last.cases$pti == 1], na.rm = T), sd(last.cases$age[last.cases$pti == 1], na.rm = T),
  mean(last.cases$age[last.cases$pti == 0], na.rm = T), sd(last.cases$age[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$female, na.rm = T), sd(last.cases$female, na.rm = T),
  mean(last.cases$female[last.cases$pti == 1], na.rm = T), sd(last.cases$female[last.cases$pti == 1], na.rm = T),
  mean(last.cases$female[last.cases$pti == 0], na.rm = T), sd(last.cases$female[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$race4 == "B", na.rm = T), sd(last.cases$race4 == "B", na.rm = T),
  mean(last.cases$race4[last.cases$pti == 1] == "B", na.rm = T), sd(last.cases$race4[last.cases$pti == 1] == "B", na.rm = T),
  mean(last.cases$race4[last.cases$pti == 0] == "B", na.rm = T), sd(last.cases$race4[last.cases$pti == 0] == "B", na.rm = T)),
c(mean(last.cases$race4 == "W", na.rm = T), sd(last.cases$race4 == "W", na.rm = T),
  mean(last.cases$race4[last.cases$pti == 1] == "W", na.rm = T), sd(last.cases$race4[last.cases$pti == 1] == "W", na.rm = T),
  mean(last.cases$race4[last.cases$pti == 0] == "W", na.rm = T), sd(last.cases$race4[last.cases$pti == 0] == "W", na.rm = T)),
c(mean(last.cases$race4 == "H", na.rm = T), sd(last.cases$race4 == "H", na.rm = T),
  mean(last.cases$race4[last.cases$pti == 1] == "H", na.rm = T), sd(last.cases$race4[last.cases$pti == 1] == "H", na.rm = T),
  mean(last.cases$race4[last.cases$pti == 0] == "H", na.rm = T), sd(last.cases$race4[last.cases$pti == 0] == "H", na.rm = T)),
c(mean(last.cases$median_income_group == "Below", na.rm = T), sd(last.cases$median_income_group == "Below", na.rm = T),
  mean(last.cases$median_income_group[last.cases$pti == 1] == "Below", na.rm = T), sd(last.cases$median_income_group[last.cases$pti == 1] == "Below", na.rm = T),
  mean(last.cases$median_income_group[last.cases$pti == 0] == "Below", na.rm = T), sd(last.cases$median_income_group[last.cases$pti == 0] == "Below", na.rm = T)),
c(mean(last.cases$median_income_group == "Above", na.rm = T), sd(last.cases$median_income_group == "Above", na.rm = T),
  mean(last.cases$median_income_group[last.cases$pti == 1] == "Above", na.rm = T), sd(last.cases$median_income_group[last.cases$pti == 1] == "Above", na.rm = T),
  mean(last.cases$median_income_group[last.cases$pti == 0] == "Above", na.rm = T), sd(last.cases$median_income_group[last.cases$pti == 0] == "Above", na.rm = T)),
c(mean(last.cases$median_income_group == "Unavailable", na.rm = T), sd(last.cases$median_income_group == "Unavailable", na.rm = T),
  mean(last.cases$median_income_group[last.cases$pti == 1] == "Unavailable", na.rm = T), sd(last.cases$median_income_group[last.cases$pti == 1] == "Unavailable", na.rm = T),
  mean(last.cases$median_income_group[last.cases$pti == 0] == "Unavailable", na.rm = T), sd(last.cases$median_income_group[last.cases$pti == 0] == "Unavailable", na.rm = T)),
c(mean(last.cases$any_drug, na.rm = T), sd(last.cases$any_drug, na.rm = T),
  mean(last.cases$any_drug[last.cases$pti == 1], na.rm = T), sd(last.cases$any_drug[last.cases$pti == 1], na.rm = T),
  mean(last.cases$any_drug[last.cases$pti == 0], na.rm = T), sd(last.cases$any_drug[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$any_weapon, na.rm = T), sd(last.cases$any_weapon, na.rm = T),
  mean(last.cases$any_weapon[last.cases$pti == 1], na.rm = T), sd(last.cases$any_weapon[last.cases$pti == 1], na.rm = T),
  mean(last.cases$any_weapon[last.cases$pti == 0], na.rm = T), sd(last.cases$any_weapon[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$any_rob, na.rm = T), sd(last.cases$any_rob, na.rm = T),
  mean(last.cases$any_rob[last.cases$pti == 1], na.rm = T), sd(last.cases$any_rob[last.cases$pti == 1], na.rm = T),
  mean(last.cases$any_rob[last.cases$pti == 0], na.rm = T), sd(last.cases$any_rob[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$any_prior_case, na.rm = T), sd(last.cases$any_prior_case, na.rm = T),
  mean(last.cases$any_prior_case[last.cases$pti == 1], na.rm = T), sd(last.cases$any_prior_case[last.cases$pti == 1], na.rm = T),
  mean(last.cases$any_prior_case[last.cases$pti == 0], na.rm = T), sd(last.cases$any_prior_case[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$bond_amt_n_max, na.rm = T), sd(last.cases$bond_amt_n_max, na.rm = T),
  mean(last.cases$bond_amt_n_max[last.cases$pti == 1], na.rm = T), sd(last.cases$bond_amt_n_max[last.cases$pti == 1], na.rm = T),
  mean(last.cases$bond_amt_n_max[last.cases$pti == 0], na.rm = T), sd(last.cases$bond_amt_n_max[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$vote_pre, na.rm = T), sd(last.cases$vote_pre, na.rm = T),
  mean(last.cases$vote_pre[last.cases$pti == 1], na.rm = T), sd(last.cases$vote_pre[last.cases$pti == 1], na.rm = T),
  mean(last.cases$vote_pre[last.cases$pti == 0], na.rm = T), sd(last.cases$vote_pre[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$vote_post, na.rm = T), sd(last.cases$vote_post, na.rm = T),
  mean(last.cases$vote_post[last.cases$pti == 1], na.rm = T), sd(last.cases$vote_post[last.cases$pti == 1], na.rm = T),
  mean(last.cases$vote_post[last.cases$pti == 0], na.rm = T), sd(last.cases$vote_post[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$noteli, na.rm = T), sd(last.cases$noteli, na.rm = T),
  mean(last.cases$noteli[last.cases$pti == 1], na.rm = T), sd(last.cases$noteli[last.cases$pti == 1], na.rm = T),
  mean(last.cases$noteli[last.cases$pti == 0], na.rm = T), sd(last.cases$noteli[last.cases$pti == 0], na.rm = T)),
c(mean(last.cases$regis_before, na.rm = T), sd(last.cases$regis_before, na.rm = T),
  mean(last.cases$regis_before[last.cases$pti == 1], na.rm = T), sd(last.cases$regis_before[last.cases$pti == 1], na.rm = T),
  mean(last.cases$regis_before[last.cases$pti == 0], na.rm = T), sd(last.cases$regis_before[last.cases$pti == 0], na.rm = T)))

round(table1, 2)





